<?php
/**
 * Created by a front-end programmer.
 * User: Xwen
 * Date: 2018/2/24
 * Time: 16:37
 * Mail:lauwencn@gmail.com
 */
class LoginController extends Controller{
    public function index(){
        if(IS_POST){
            if($user = K('User')->validate($_POST['username'], $_POST['password'])){
                $_SESSION['uid'] = $user['id'];
                $_SESSION['username'] = $user['username'];
                $_SESSION['is_admin'] = $user['is_admin'];
                $_SESSION['expiration'] = time() + C('EXPIRATION');
//                P($_SESSION);die;
                $this->success('登录成功', __APP__);
            }
            $this->error('登录失败');

        }
        $this->display();
    }
    public function out(){
        session_unset();
        session_destroy();
        $this->success('退出成功', __APP__.'?c=Login');
    }
}

?>